Cannot convert []string to []interface {}
        Posted  
        
            by 
                karlrh
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by karlrh
        
        
        
        Published on 2012-10-20T16:19:25Z
        Indexed on 
            2012/10/20
            17:01 UTC
        
        
        Read the original article
        Hit count: 163
        
I'm writing some code, and I need it to catch the arguments and pass them through fmt.Println (I want its default behaviour, to write arguments separated by spaces and followed by a newline). However it takes []interface {} but flag.Args() returns a []string. Here's the code example
package main
import (
    "fmt"
    "flag"
)
func main() {
    flag.Parse()
    fmt.Println(flag.Args()...)
}
This returns the following error:
./example.go:10: cannot use args (type []string) as type []interface {} in function argument
Is this a bug? Shouldn't fmt.Println take any array? By the way, I've also tried to do this:
var args = []interface{}(flag.Args())
but I get the following error:
cannot convert flag.Args() (type []string) to type []interface {}
Is there a "Go" way to workaround this?
© Stack Overflow or respective owner